//
//  MapKitViewController.swift
//  UI
//
//  Created by admin on 14/9/22.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//
/*
@availability(iOS, introduced=5.0)
enum MKUserTrackingMode : Int {
case None // the user's location is not followed
case Follow // the map follows the user's location
case FollowWithHeading // the map follows the user's location and heading
}

@availability(iOS, introduced=3.0)
class MKMapView : UIView, NSCoding {

weak var delegate: MKMapViewDelegate!

// Changing the map type or region can cause the map to start loading map content.
// The loading delegate methods will be called as map content is loaded.
var mapType: MKMapType

// Region is the coordinate and span of the map.
// Region may be modified to fit the aspect ratio of the view using regionThatFits:.
var region: MKCoordinateRegion
func setRegion(region: MKCoordinateRegion, animated: Bool)

// centerCoordinate allows the coordinate of the region to be changed without changing the zoom level.
var centerCoordinate: CLLocationCoordinate2D
func setCenterCoordinate(coordinate: CLLocationCoordinate2D, animated: Bool)

// Returns a region of the aspect ratio of the map view that contains the given region, with the same center point.
func regionThatFits(region: MKCoordinateRegion) -> MKCoordinateRegion

// Access the visible region of the map in projected coordinates.
var visibleMapRect: MKMapRect
func setVisibleMapRect(mapRect: MKMapRect, animated animate: Bool)

// Returns an MKMapRect modified to fit the aspect ratio of the map.
func mapRectThatFits(mapRect: MKMapRect) -> MKMapRect

// Edge padding is the minumum padding on each side around the specified MKMapRect.

func setVisibleMapRect(mapRect: MKMapRect, edgePadding insets: UIEdgeInsets, animated animate: Bool)
func mapRectThatFits(mapRect: MKMapRect, edgePadding insets: UIEdgeInsets) -> MKMapRect

@availability(iOS, introduced=7.0)
@NSCopying var camera: MKMapCamera!
@availability(iOS, introduced=7.0)
func setCamera(camera: MKMapCamera!, animated: Bool)

func convertCoordinate(coordinate: CLLocationCoordinate2D, toPointToView view: UIView!) -> CGPoint
func convertPoint(point: CGPoint, toCoordinateFromView view: UIView!) -> CLLocationCoordinate2D
func convertRegion(region: MKCoordinateRegion, toRectToView view: UIView!) -> CGRect
func convertRect(rect: CGRect, toRegionFromView view: UIView!) -> MKCoordinateRegion

// Control the types of user interaction available
// Zoom and scroll are enabled by default.
var zoomEnabled: Bool
var scrollEnabled: Bool
// Rotate and pitch are enabled by default on Mac OS X and on iOS 7.0 and later.
@availability(iOS, introduced=7.0)
var rotateEnabled: Bool
@availability(iOS, introduced=7.0)
var pitchEnabled: Bool

@availability(iOS, introduced=7.0)
var showsPointsOfInterest: Bool // Affects MKMapTypeStandard and MKMapTypeHybrid
@availability(iOS, introduced=7.0)
var showsBuildings: Bool // Affects MKMapTypeStandard

// Set to YES to add the user location annotation to the map and start updating its location
var showsUserLocation: Bool

// The annotation representing the user's location
var userLocation: MKUserLocation! { get }

@availability(iOS, introduced=5.0)
var userTrackingMode: MKUserTrackingMode
@availability(iOS, introduced=5.0)
func setUserTrackingMode(mode: MKUserTrackingMode, animated: Bool)

// Returns YES if the user's location is displayed within the currently visible map region.
var userLocationVisible: Bool { get }

// Annotations are models used to annotate coordinates on the map.
// Implement mapView:viewForAnnotation: on MKMapViewDelegate to return the annotation view for each annotation.
func addAnnotation(annotation: MKAnnotation!)
func addAnnotations(annotations: [AnyObject]!)

func removeAnnotation(annotation: MKAnnotation!)
func removeAnnotations(annotations: [AnyObject]!)

var annotations: [AnyObject]! { get }
@availability(iOS, introduced=4.2)
func annotationsInMapRect(mapRect: MKMapRect) -> NSSet!

// Currently displayed view for an annotation; returns nil if the view for the annotation isn't being displayed.
func viewForAnnotation(annotation: MKAnnotation!) -> MKAnnotationView!

// Used by the delegate to acquire an already allocated annotation view, in lieu of allocating a new one.
func dequeueReusableAnnotationViewWithIdentifier(identifier: String!) -> MKAnnotationView!

// Select or deselect a given annotation.  Asks the delegate for the corresponding annotation view if necessary.
func selectAnnotation(annotation: MKAnnotation!, animated: Bool)
func deselectAnnotation(annotation: MKAnnotation!, animated: Bool)
var selectedAnnotations: [AnyObject]!

// annotationVisibleRect is the visible rect where the annotations views are currently displayed.
// The delegate can use annotationVisibleRect when animating the adding of the annotations views in mapView:didAddAnnotationViews:
var annotationVisibleRect: CGRect { get }

// Position the map such that the provided array of annotations are all visible to the fullest extent possible.
@availability(iOS, introduced=7.0)
func showAnnotations(annotations: [AnyObject]!, animated: Bool)
}

@availability(iOS, introduced=7.0)
enum MKOverlayLevel : Int {
case AboveRoads // note that labels include shields and point of interest icons.
case AboveLabels
}

extension MKMapView {

// Overlays are models used to represent areas to be drawn on top of the map.
// This is in contrast to annotations, which represent points on the map.
// Implement -mapView:rendererForOverlay: on MKMapViewDelegate to return the renderer for each overlay.
@availability(iOS, introduced=7.0)
func addOverlay(overlay: MKOverlay!, level: MKOverlayLevel)
@availability(iOS, introduced=7.0)
func addOverlays(overlays: [AnyObject]!, level: MKOverlayLevel)

@availability(iOS, introduced=4.0)
func removeOverlay(overlay: MKOverlay!)
@availability(iOS, introduced=4.0)
func removeOverlays(overlays: [AnyObject]!)

@availability(iOS, introduced=7.0)
func insertOverlay(overlay: MKOverlay!, atIndex index: Int, level: MKOverlayLevel)

@availability(iOS, introduced=4.0)
func insertOverlay(overlay: MKOverlay!, aboveOverlay sibling: MKOverlay!)
@availability(iOS, introduced=4.0)
func insertOverlay(overlay: MKOverlay!, belowOverlay sibling: MKOverlay!)

@availability(iOS, introduced=7.0)
func exchangeOverlay(overlay1: MKOverlay!, withOverlay overlay2: MKOverlay!)

@availability(iOS, introduced=4.0)
var overlays: [AnyObject]! { get }
@availability(iOS, introduced=7.0)
func overlaysInLevel(level: MKOverlayLevel) -> [AnyObject]!

// Current renderer for overlay; returns nil if the overlay is not shown.
@availability(iOS, introduced=7.0)
func rendererForOverlay(overlay: MKOverlay!) -> MKOverlayRenderer!

// Currently displayed view for overlay; returns nil if the view has not been created yet.
// Prefer using MKOverlayRenderer and -rendererForOverlay.

// These methods operate implicitly on overlays in MKOverlayLevelAboveLabels and may be deprecated in a future release in favor of the methods that specify the level.
@availability(iOS, introduced=4.0)
func addOverlay(overlay: MKOverlay!)
@availability(iOS, introduced=4.0)
func addOverlays(overlays: [AnyObject]!)

@availability(iOS, introduced=4.0)
func insertOverlay(overlay: MKOverlay!, atIndex index: Int)
@availability(iOS, introduced=4.0)
func exchangeOverlayAtIndex(index1: Int, withOverlayAtIndex index2: Int)
}

protocol MKMapViewDelegate : NSObjectProtocol {


}
*/
import UIKit
import MapKit

class MapKitViewController: UIViewController,CLLocationManagerDelegate {

    @IBOutlet var map: MKMapView!
    var locManager : CLLocationManager!

    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //1,
        self.locManager = CLLocationManager()

        //2,
        
        //3,
        self.locManager.delegate = self
        self.locManager.desiredAccuracy = kCLLocationAccuracyBest
        
        //4,
        self.locManager.distanceFilter = 5.0
        //5,
        self.locManager.startUpdatingLocation()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK: -CLLocationManagerDelegate
    func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!){
        println("error=\(error)")
        return
    }
    
    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){
        var location : CLLocation = locations.last as CLLocation
        println("locations=\(location.description)")
        println("locations=\(location.speed)")
        
        
    }
    
    
    //MARK: -MKMapViewDelegate
    func mapView(mapView: MKMapView!, regionWillChangeAnimated animated: Bool){
    
    }
    func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool){

    }
    
    func mapViewWillStartLoadingMap(mapView: MKMapView!){
    
    }
    func mapViewDidFinishLoadingMap(mapView: MKMapView!){
    
    }
    func mapViewDidFailLoadingMap(mapView: MKMapView!, withError error: NSError!){
    
    }
    
    @availability(iOS, introduced=7.0)
    func mapViewWillStartRenderingMap(mapView: MKMapView!){
    
    }
    @availability(iOS, introduced=7.0)
    func mapViewDidFinishRenderingMap(mapView: MKMapView!, fullyRendered: Bool){
    
    }
    
    // mapView:viewForAnnotation: provides the view for each annotation.
    // This method may be called for all or some of the added annotations.
    // For MapKit provided annotations (eg. MKUserLocation) return nil to use the MapKit provided annotation view.
//    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!{
//    
//    }
    
    // mapView:didAddAnnotationViews: is called after the annotation views have been added and positioned in the map.
    // The delegate can implement this method to animate the adding of the annotations views.
    // Use the current positions of the annotation views as the destinations of the animation.
    func mapView(mapView: MKMapView!, didAddAnnotationViews views: [AnyObject]!){
    
    }
    
    // mapView:annotationView:calloutAccessoryControlTapped: is called when the user taps on left & right callout accessory UIControls.
    func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!){
    
    }
    
    @availability(iOS, introduced=4.0)
    func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!){
    
    }
    @availability(iOS, introduced=4.0)
    func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!){
    
    }
    
    @availability(iOS, introduced=4.0)
    func mapViewWillStartLocatingUser(mapView: MKMapView!){
    
    }
    @availability(iOS, introduced=4.0)
    func mapViewDidStopLocatingUser(mapView: MKMapView!){
    
    }
    @availability(iOS, introduced=4.0)
    func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!){
    
    }
    @availability(iOS, introduced=4.0)
    func mapView(mapView: MKMapView!, didFailToLocateUserWithError error: NSError!){
    
    }
    
    @availability(iOS, introduced=4.0)
    func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, didChangeDragState newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState){
    
    }
    
    @availability(iOS, introduced=5.0)
    func mapView(mapView: MKMapView!, didChangeUserTrackingMode mode: MKUserTrackingMode, animated: Bool){
        
    }
    
    @availability(iOS, introduced=7.0)
//    func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer!{
//        
//    }
    @availability(iOS, introduced=7.0)
    func mapView(mapView: MKMapView!, didAddOverlayRenderers renderers: [AnyObject]!){
    
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
